<template>
  <div class="mcontaner">
    <Header></Header>

    <div class="block">
      <el-timeline>
        <el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs">
          <el-card>
            <h4>
              <!--通过路由跳转，path: '/blog/:blogId',-->
              <router-link :to="{name: 'BlogDetail',params: {blogId: blog.id}}">
                {{blog.title}}
              </router-link>
            </h4>
            <p>{{blog.description}}</p>
          </el-card>
        </el-timeline-item>

      </el-timeline>

      <el-pagination class="mpage"
                     background
                     layout="prev, pager, next"
                     :current-page="currentPage"
                     :page-size="pageSize"
                     :total="total"
                     @current-change=page
      >
      </el-pagination>

    </div>

  </div>
</template>

<script>
//导入公共部分
import Header from "../components/Header"
export default {
  name: "Blogs.vue",
  components: {Header},
  data() {
    return {
      blogs: {},
      currentPage: 1,
      total: 0,
      pageSize: 5
    }
  },
  methods: {
    page(currentPage) {
      const _this = this
      ///blogs?currentPage=   传入分页的信息
      _this.axios.get("/blogs?currentPage=" + currentPage).then(res => {
        console.log(res)
        var data = res.data.data
        _this.blogs = data.records
        _this.currentPage = data.current
        _this.total = data.total
        _this.pageSize = data.size
      })
    }
  },
  created(){  //数据回显，开始即调用分页
    this.page(1)
  }
}
</script>

<style scoped>

  .block {
    margin: 20px;
  }

  .mpage {
    margin: 0 auto;
  }

</style>